package com.thinkinghead.mahjongrecorder.ui.textdialog;


import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.widget.EditText;

public class TextDialog {

	private OnTextListener mlistener = null;
	private String defaultText = "";
	private Context mContext = null;
	private AlertDialog.Builder alert = null;
	private EditText input = null;
	
	public TextDialog(Context context, OnTextListener mlistener,
			String defaultText,String title) {
		this.mContext = context;
		this.mlistener = mlistener;
		this.defaultText = defaultText;
		fnCreate();
	}
	
	public TextDialog(Context context, OnTextListener mlistener,
			String defaultText) {
		this.mContext = context;
		this.mlistener = mlistener;
		this.defaultText = defaultText;
		fnCreate();
	}
	
	public void show(){
		alert.show();
	}
	
	public void setTitle(String title) {
		this.alert.setTitle(title);
	}

	public void setMessage(String msg) {
		this.alert.setMessage(msg);
	}

	private void fnCreate() {
		alert = new AlertDialog.Builder(mContext);
		alert.setCancelable(true);
		
		input = new EditText(mContext);
		input.setText(defaultText);
		alert.setView(input);
		
		alert.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int whichButton) {
				mlistener.textValue(input.getText().toString());
			}
		});
	}
}